package com.noocodecommit.wicket.jquery.plugin.ui.slider;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.Model;

import com.noocodecommit.wicket.jquery.TemplatePage;
import com.noocodecommit.wicket.stuff.jquery.JQCore;
import com.noocodecommit.wicket.stuff.jquery.plugin.chili.JQChili;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.slider.JQSlider;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.slider.JQSliderUtils;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.slider.OnSlideStartBehavior;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.slider.OnSlideStopBehavior;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.tabs.JQTabs;

public class SliderPage extends TemplatePage
{

	private static final long serialVersionUID = 1L;
	private final JQTabs tabContainer;

	public SliderPage()
	{
		super();
		JQCore.init(this);
		this.setupChili();

		tabContainer = new JQTabs("tab-container");
		tabContainer.setOutputMarkupId(true);
		add(tabContainer);

		/**********************
		 * Simple Slider
		 **********************/
		JQSlider slider0 = JQSliderUtils.create("slider0", false, JQSlider.STYLE_SLIDER_1).build();
		tabContainer.add(slider0);

		/**********************
		 * Ajax Selectable #1
		 **********************/
		final Label value1 = new Label("value1");
		value1.setOutputMarkupId(true);
		tabContainer.add(value1);

		JQSlider slider1 = JQSliderUtils.create("slider1", false, JQSlider.STYLE_SLIDER_2).slideScript("$('#" + value1.getMarkupId() + "').html(ui.value);").build();
		tabContainer.add(slider1);

		final Label output1 = new Label("output1");
		output1.setOutputMarkupId(true);
		tabContainer.add(output1);

		slider1.add(new OnSlideStartBehavior()
		{
			public void onStart(AjaxRequestTarget target)
			{
				String msg = String.format("slide start value is '%d'", ((JQSlider) this.getComponent()).getValue());
				output1.setModel(new Model(msg));
				target.addComponent(output1);
			}
		});

		slider1.add(new OnSlideStopBehavior()
		{
			public void onStop(AjaxRequestTarget target)
			{
				String msg = String.format("slide stop value is '%d'", ((JQSlider) this.getComponent()).getValue());
				output1.setModel(new Model(msg));
				target.addComponent(output1);
			}
		});

		JQChili chili1 = new JQChili("chili1");
		add(chili1);
		this.bindChiliCode(chili1, this.getClass(), "html");

		JQChili chili2 = new JQChili("chili2");
		add(chili2);
		this.bindChiliCode(chili2, this.getClass(), "java");

		JQCore.get().bindOnDocumentReadyFunction();
	}
}
